From 6c2f0e4cbf7253256c457e77d032596e30a98192 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 31 Oct 2025 04:37:49 +0100 Subject: [PATCH] tests/shell: Add basic multi-monitor test We only care about creating a new monitor and ensure that the new geometries respect the monitors setup Part-of: --- tests/meson.build | 3 ++ tests/shell/multiMonitor.js | 64 +++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 tests/shell/multiMonitor.js diff --git a/tests/meson.build b/tests/meson.build index f51d1e8c2..373bf90e9 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -85,6 +85,9 @@ shell_tests = [ { 'name': 'closeWithActiveWindows', }, + { + 'name': 'multiMonitor', + }, { 'name': 'headlessStart', 'options': ['--hotplug'], diff --git a/tests/shell/multiMonitor.js b/tests/shell/multiMonitor.js new file mode 100644 index 000000000..d69890a04 --- /dev/null +++ b/tests/shell/multiMonitor.js @@ -0,0 +1,64 @@ +import MetaTest from 'gi://MetaTest'; + +import * as Main from 'resource:///org/gnome/shell/ui/main.js'; + +/** + * init: + */ +export function init() {} + +/** + * run: + */ +export async function run() { + const monitorsChangedPromise = new Promise(resolve => { + const monitorsChangedHandlerId = Main.layoutManager.connect('monitors-changed', + () => { + Main.layoutManager.disconnect(monitorsChangedHandlerId); + resolve(); + }); + }); + + MetaTest.TestMonitor.new(global.context, 1280, 720, 60.0); + await monitorsChangedPromise; +} + +function expectEqual(a, b, desc = null) { + if (a !== b) + throw new Error(`${desc ? `${desc} ` : ''}${a} does not match ${b}`); +} + +/** + * finish: + */ +export function finish() { + const monitors = []; + + expectEqual(global.display.get_n_monitors(), 2, 'Configured monitors'); + + for (let i = 0; i < global.display.get_n_monitors(); ++i) + monitors.push(global.display.get_monitor_geometry(i)); + + const expectedScreenWidth = monitors.reduce((sum, m) => sum + m.width, 0); + const expectedScreenHeight = monitors.reduce((max, m) => Math.max(max, m.height), 0); + console.log(`Expecting screen to have size of: ${expectedScreenWidth}x${expectedScreenHeight}`); + + expectEqual(global.screen_width, expectedScreenWidth, 'Screen Width'); + expectEqual(global.screen_height, expectedScreenHeight, 'Screen Height'); + + expectEqual(global.stage.width, global.screen_width, 'Stage Width'); + expectEqual(global.stage.height, global.screen_height, 'Stage Height'); + + expectEqual(Main.layoutManager.monitors.length, monitors.length, 'Monitors length'); + expectEqual(Main.layoutManager.primaryMonitor, Main.layoutManager.monitors[0], 'Primary Monitor'); + expectEqual(Main.layoutManager._bgManagers.length, monitors.length, 'Background Managers length'); + + for (let i = 0; i < monitors.length; ++i) { + const monitor = Main.layoutManager.monitors[i]; + expectEqual(monitor.index, i, `Monitor ${i} index`); + expectEqual(monitor.x, monitors[i].x, `Monitor ${i} x`); + expectEqual(monitor.y, monitors[i].y, `Monitor ${i} y`); + expectEqual(monitor.width, monitors[i].width, `Monitor ${i} width`); + expectEqual(monitor.height, monitors[i].height, `Monitor ${i} height`); + } +} -- 2.39.5